// ****************************************************************
// Dates.java
//
// Determine whether a 2nd-millenium date entered by the user
// is valid          
// ****************************************************************
import java.util.Scanner;

public class Dates
{
    public static void main(String[] args)
    {
	int year, month, day;   //date read in from user
	int daysInMonth;        //number of days in month read in 
	boolean monthValid, yearValid, dayValid;  //true if input from user is valid
	boolean leapYear;       //true if user's year is a leap year
	int[] monthDays = {
			31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	
      Scanner scan = new Scanner(System.in);

	//Get integer month, day, and year from user
    System.out.println("What year?");
    year = scan.nextInt();
    System.out.println("What month?");
    month = scan.nextInt();
    System.out.println("What day?");
    day = scan.nextInt();
    //Check to see if month is valid
    monthValid = ( 0 < month && month < 13);
    if (!monthValid)
    {
    	month = 1;
    }
    //Check to see if year is valid
    yearValid = ( 999 < year && year < 2000);
    //Determine whether it's a leap year
    if (year % 4 == 0)
    {
    	if (year % 1000 == 0)
    	{
    		leapYear = (year % 400 == 0);
    	}
    	else
    	{
    		leapYear = false;
    	}
    }
    else
    {
    	leapYear = false;
    }
	//Determine number of days in month
    if (leapYear && (month == 2))
    {
    	daysInMonth = 29;
    }
    else
    {
    	daysInMonth = monthDays[(month - 1)];
    }
	//User number of days in month to check to see if day is valid
    dayValid = ( 0 < day && day <= daysInMonth );
	//Determine whether date is valid and print appropriate message
    if (yearValid && monthValid && dayValid)
    {
    	System.out.println("The date is valid.");
    	if (leapYear)
    	{
    		System.out.println("The year is a leap year.");
    	}
    }
    else
    {
    	System.out.println("The date is invalid.");
    }
    scan.close();
    }
}